<?php
/**
 * 数据插件抽象类
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Plugin.php 1059 2011-11-18 09:26:15Z mmxie $
 */
abstract class IG_Data_Plugin extends IG_Data_FactoryAbstract
{

    /**
     * IG_Data_Source
     * @param array|Zend_Config $config
     * @return IG_Data_Plugin
     */
    public static function factory($config)
    {
        return self::_factory($config, __CLASS__);
    }


    /**
     * @return IG_Data_Source
     */
    public function getSource()
    {
        return IG_Data::$adapter->getSource();
    }

    /**
     * @return Zend_View_Interface|null
     */
    public function getView()
    {
        return IG_Data::$adapter->getView();
    }

    /**
     * @return Zend_Controller_Request_Abstract
     */
    public function getRequest()
    {
        return IG_Data::$adapter->getRequest();
    }

    public function __construct($config)
    {
        if (!empty($config)) {
            foreach ($config as $key => $val) {
                $this->{"set$key"}($val);
            }
        }
    }

    public function __call($method, $params)
    {
        throw new IG_Exception("未知方法'$method'");
    }

    public function before()
    {}

    public function after()
    {}

    public function beforeXmlHttpRequest()
    {
        return $this->before();
    }

    public function afterXmlHttpRequest()
    {
        return $this->after();
    }
}